package com.reconcile.phone.web.controller.system;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reconcile.phone.business.domain.bo.RpPhoneCodeBo;
import com.reconcile.phone.business.domain.vo.RpPhoneCodeVo;
import com.reconcile.phone.business.service.RpPhoneCodeService;
import com.reconcile.phone.common.annotation.RepeatSubmit;
import com.reconcile.phone.common.core.controller.BaseController;
import com.reconcile.phone.common.core.domain.PageQuery;
import com.reconcile.phone.common.core.domain.R;
import com.reconcile.phone.common.core.validate.AddGroup;
import com.reconcile.phone.common.core.validate.EditGroup;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.concurrent.TimeUnit;

/**
 * 后台 手机号管理
 *
 * Author: liuliyou
 * Date: 2025/8/9
 */
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/system/phoneCode")
public class SysRpPhoneCodeController extends BaseController {

    private final RpPhoneCodeService rpPhoneCodeService;

    /**
     * 新增手机号
     *
     * @param bo 手机号信息
     * @return 新增结果
     */
    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "5s秒内请勿重复操作")
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody RpPhoneCodeBo bo) {
        return toAjax(rpPhoneCodeService.insertPhoneCode(bo));
    }

    /**
     * 编辑手机号
     *
     * @param bo 手机号信息
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public R<Void> update(@Validated(EditGroup.class) @RequestBody RpPhoneCodeBo bo) {
        return toAjax(rpPhoneCodeService.updatePhoneCode(bo));
    }

    /**
     * 手机号表查询
     *
     * @param bo
     * @param pageQuery
     * @return
     */
    @GetMapping("/list")
    public R<Page<RpPhoneCodeVo>> list(RpPhoneCodeBo bo, PageQuery pageQuery) {
        return R.ok(rpPhoneCodeService.selectPhoneCodeList(bo, pageQuery));
    }

    /**
     * 手机号详细信息
     *
     * @param phoneCodeId 主键
     */
    @GetMapping("/{phoneCodeId}")
    public R<RpPhoneCodeVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long phoneCodeId) {
        return R.ok(rpPhoneCodeService.queryPhoneCodeById(phoneCodeId));
    }

    /**
     * 删除手机号
     *
     * @param phoneCodeId 主键
     */
    @GetMapping("/delete/{phoneCodeId}")
    public R<Void> delete(@NotNull(message = "主键不能为空") @PathVariable Long phoneCodeId) {
        return toAjax(rpPhoneCodeService.deletePhoneCodeById(phoneCodeId));
    }
}
